<template>
    <div>
        <el-row type="flex" :gutter="10" style="margin-bottom: 25px">
            <!-- 相关数据 -->
            <el-col :span="5">
                <el-card>
                    今日需照蛋数量:<i
                        style="
                            font-size: 16px;
                            font-weight: 900;
                            color: #ffd700;
                        "
                        >{{ needPictureEggNum }}</i
                    >
                    个
                </el-card>
            </el-col>
            <el-col :span="5">
                <el-card>
                    今日需抽蛋数量:<i
                        style="
                            font-size: 16px;
                            font-weight: 900;
                            color: #ee9a00;
                        "
                        >{{ needTakeEggsNum }}</i
                    >
                    个
                </el-card>
            </el-col>
            <el-col :span="5">
                <el-card>
                    今日需查仔数量：<i
                        style="
                            font-size: 16px;
                            font-weight: 900;
                            color: #03a9f4;
                        "
                        >{{ needCheckDovesNum }}</i
                    >
                    个
                </el-card>
            </el-col>
            <el-col :span="5">
                <el-card>
                    昨日垫蛋数量：<i
                        style="
                            font-size: 16px;
                            font-weight: 900;
                            color: #9acd32;
                        "
                        >{{ matEggsOfYesterdayNum }}</i
                    >
                    个
                </el-card>
            </el-col>
            <el-col :span="5">
                <!-- 后面需要对获取到的数据进行处理，是 fiAbnormalVoOfYesterdayNum-->
                <el-card>
                    昨日异常统计：<i
                        style="
                            font-size: 16px;
                            font-weight: 900;
                            color: #ff4040;
                        "
                        >{{ fiAbnormalVoOfYesterdayNum }}</i
                    >个
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>
<script>
import { mapState } from "vuex";
import {
    getNeedTakeEggs,
    getNeedPictureEgg, 
    getNeedCheckDoves,
    getMatEggsOfYesterday,
    getAbnormalVoOfYesterday,
} from "../../../api/Dovecote/InfoManage/dataCount.js";
export default {
    name: "dataCount",
    created() {
        // console.log("组件创建");
        // console.log(this.currentDovecote, "当前鸽棚");
        if (this.currentDovecote.baseId) {
            this.getNeedPictureEggNum(); //今日需照蛋数量
            this.getNeedTakeEggsNum(); //今日需抽蛋数量
            this.getNeedCheckDovesNum(); //今日需要查仔数量
            this.getMatEggsOfYesterdayNum(); //昨日垫蛋数量
            this.getAbnormalVoOfYesterdayNum(); //昨日异常数量
            this.$emit('getAllData',this.allData); //将数据传给父组件
            // console.log('所有数据',this.allData)
        }
    },
    mounted() {
        // console.log("mounted中试试", this.currentDovecote);
    },
    data() {
        return {
            //获取照蛋数量所需参数
            needPictureEggParams: {
                baseId: "",
                dovecoteNumber: "",
            },
            //获取抽蛋数量所需参数
            needTakeEggsParams: {
                baseId: "",
                dovecoteNumber: "",
            },
            //获取查仔数量所需参数
            needCheckDovesParams: {
                baseId: "",
                dovecoteNumber: "",
            },
            //获取垫蛋数量所需参数
            matEggsOfYesterdayParams: {
                baseId: "",
                dovecoteNumber: "",
            },
            //昨日异常数量所需参数
            abnormalVoOfYesterdayParams: {
                baseId: "",
                dovecoteNumber: "",
            },
            //需要抽蛋的数量
            needTakeEggsNum: "",
            //需要照蛋的数量
            needPictureEggNum: "",
            //需要查仔数量
            needCheckDovesNum: "",
            //昨日垫蛋数量
            matEggsOfYesterdayNum: "",
            //昨日异常数量
            abnormalVoOfYesterdayNum: "",
            //昨日异常数量最终数据
            fiAbnormalVoOfYesterdayNum: "",
            allData: [], //各种异常数据得到的数组
        };
    },
    methods: {
        //今日需抽蛋数量
        async getNeedTakeEggsNum() {
            // console.log("我在获取抽蛋数量");
            this.needTakeEggsParams.baseId = this.currentDovecote.baseId;
            this.needTakeEggsParams.dovecoteNumber =
                this.currentDovecote.dovecoteNumber;
            // console.log("鸽棚数据", this.currentDovecote);
            // console.log("照蛋参数", this.needTakeEggsParams);

            let { data } = await getNeedTakeEggs(this.needTakeEggsParams);
            // console.log(data);
            // console.log("后执行");

            if (data.statusCode === 20000) {
                this.needTakeEggsNum = data.data;
                let dataTemp = {
                    name: "今日抽蛋",
                    value: data.data,
                };
                this.allData.push(dataTemp);
            }
        },

        //今日需照蛋数量
        async getNeedPictureEggNum() {
            let that = this;
            // console.log(that.needPictureEggParams)
            that.needPictureEggParams.baseId = that.currentDovecote.baseId;
            that.needPictureEggParams.dovecoteNumber =
                that.currentDovecote.dovecoteNumber;

            let { data } = await getNeedPictureEgg(that.needPictureEggParams);
            // console.log("我在获取照蛋数量");
            // console.log(data);

            if (data.statusCode === 20000) {
                that.needPictureEggNum = data.data;
                let dataTemp = {
                    name: "今日照蛋",
                    value: data.data,
                };
                this.allData.push(dataTemp);
            }
        },

        //今日需要查仔数量
        async getNeedCheckDovesNum() {
            let that = this;
            this.needCheckDovesParams.baseId = this.currentDovecote.baseId;
            this.needCheckDovesParams.dovecoteNumber =
                this.currentDovecote.dovecoteNumber;
            // console.log("数据", this.currentDovecote);
            // console.log("查仔参数", that.needCheckDovesParams);

            let { data } = await getNeedCheckDoves(that.needCheckDovesParams);
            // console.log("我在获取查仔数量", data);
            // console.log();

            if (data.statusCode === 20000) {
                that.needCheckDovesNum = data.data;
                let dataTemp = {
                    name: "今日查仔",
                    value: data.data,
                };
                this.allData.push(dataTemp);
            }
        },

        //昨日垫蛋数量
        async getMatEggsOfYesterdayNum() {
            let that = this;

            this.matEggsOfYesterdayParams.baseId = this.currentDovecote.baseId;
            this.matEggsOfYesterdayParams.dovecoteNumber =
                this.currentDovecote.dovecoteNumber;

            let { data } = await getMatEggsOfYesterday(
                this.matEggsOfYesterdayParams
            );
            // console.log("我在获取垫蛋数量");
            // console.log(data);

            if (data.statusCode === 20000) {
                this.matEggsOfYesterdayNum = data.data;
                let dataTemp = {
                    name: "今日垫蛋",
                    value: data.data,
                };
                this.allData.push(dataTemp);
            }
        },

        //昨日异常数量
        async getAbnormalVoOfYesterdayNum() {
            this.abnormalVoOfYesterdayParams.baseId =
                this.currentDovecote.baseId;
            this.abnormalVoOfYesterdayParams.dovecoteNumber =
                this.currentDovecote.dovecoteNumber;

            let { data } = await getAbnormalVoOfYesterday(
                this.abnormalVoOfYesterdayParams
            );
            // console.log("我在获取异常数量");
            // console.log(data);

            if (data.statusCode === 20000) {
                // console.log(data.data);
                this.abnormalVoOfYesterdayNum = data.data; //要进行处理，最终数据是fiAbnormalVoOfYesterdayNum
                this.fiAbnormalVoOfYesterdayNum = 0;

                this.abnormalVoOfYesterdayNum.forEach((item) => {
                    //获取每种异常的数量进行累加
                    this.fiAbnormalVoOfYesterdayNum += item.amount;
                });
                // console.log(this.fiAbnormalVoOfYesterdayNum);
                let dataTemp = {
                    name: "昨日异常",
                    value: this.fiAbnormalVoOfYesterdayNum,
                };
                this.allData.push(dataTemp);
            }
        },
    },
    computed: {
        // ...mapState({
        //     currentDovecote: (
        //         state //当前鸽棚信息
        //     ) => state.Usersetting.CurrentDovecote,
        // }),
        currentDovecote: function () {
            return this.$store.state.Usersetting.CurrentDovecote;
        },
    },
};
</script>
<style >
</style>